package xyz.kail.demo.consul.client.discovery;

import com.google.common.net.HostAndPort;
import com.orbitz.consul.AgentClient;
import com.orbitz.consul.Consul;
import com.orbitz.consul.model.agent.Agent;
import com.orbitz.consul.model.agent.Config;

import java.io.IOException;
import java.net.URL;

/**
 * @author Kail
 * @since 2018/1/16.
 */
public class DiscoveryHelloMain {

    static Consul consul = Consul.builder().withHostAndPort(HostAndPort.fromParts("localhost", 8511)).build();

    public static void main(String[] args) throws IOException {

        AgentClient agentClient = consul.agentClient();

        agentClient.register(80, new URL("http://localhost"), 10L, "nginx", "123", "localhost");

    }

    private static void printAgent(AgentClient agentClient) {
        Agent agent = agentClient.getAgent();

        Config config = agent.getConfig();

        System.out.println(config.getDatacenter());
        System.out.println(config.getServer());
        System.out.println(config.getRevision());
        System.out.println(config.getNodeName());
        System.out.println(config.getVersion());

    }

}
